package com.zy.web.demo.duoxiancheng.demo32;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author <a href="mailto:zhouyong@cqyyt.com">zy</a>
 * @version 1.0
 * @date 2020/9/7 15:37
 */
public class Service32 {

    private ReentrantLock lock;

    public Service32(boolean isFair) {
        this.lock = new ReentrantLock(isFair);
    }

    public void method(){
        lock.lock();
        try {
            System.out.println("公平锁的情况"+lock.isFair());
        }finally {
            lock.unlock();
        }
    }

    public void methodA(){
        System.out.println(lock.isHeldByCurrentThread());
        lock.lock();
        try {
            System.out.println(lock.isHeldByCurrentThread());
        }finally {
            lock.unlock();
        }
    }
}
